import request from '@/config/axios'
import type { PrintTemplate } from './types'
import { useCache } from '@/hooks/web/useCache'
const { wsCache } = useCache()

export const getPrintTemplatesListApi = (params: any): Promise<IResponse> => {
  return request.get({ url: '/print-templates', params })
}

export const createPrintTemplatesApi = (data: Partial<PrintTemplate>): Promise<IResponse> => {
  return request.post({ url: '/print-templates', data })
}

export const updatePrintTemplatesApi = (
  id: string,
  data: Partial<PrintTemplate>
): Promise<IResponse> => {
  return request.put({ url: `/print-templates/id/${id}`, data })
}

export const getPrintTemplatesDetailApi = (id: string): Promise<IResponse<PrintTemplate>> => {
  return request.get({ url: `/print-templates/id/${id}` })
}

export const delPrintTemplatesListApi = (ids: string[] | number[]): Promise<IResponse> => {
  return request.delete({ url: `/print-templates/id/${ids[0]}` })
}

export const sendToPrinterApi = (data: any, printCount: number): Promise<IResponse> => {
  return request.post({
    url: `${wsCache.get('printer_service') || 'http://127.0.0.1:9600'}/print?count=${printCount}`,
    data
  })
}

export const getPrinterService = () => {
  return wsCache.get('printer_service') || 'http://127.0.0.1:9600'
}
